/**
 * Creating a sidebar enables you to:
 - create an ordered group of docs
 - render a sidebar for each doc of that group
 - provide next/previous navigation

 The sidebars can be generated from the filesystem, or explicitly defined here.

 Create as many sidebars as you want.
 */


import {readFileSync} from "fs";

function getCategories(path) {
  const fileContent = readFileSync(`${__dirname}/${path}`, 'utf8');
  const jsonData = JSON.parse(fileContent);
  return Array.from(new Set(jsonData.map(item => item.category)));
}

const CategoriesExamples = getCategories("./src/data/examples.json");
const CategoriesNodes = getCategories("./src/data/nodes.json");

// @ts-check

/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */


const sidebars = {
  // By default, Docusaurus generates a sidebar from the docs folder structure
  // tutorialSidebar: [{ type: "autogenerated", dirName: "." }],

  // But you can create a sidebar manually
  guides: [
    {
      type: "category",
      label: "Guides",
      link: { type: "doc", id: "guides/readme" },
      items: [
        {
          type: "autogenerated",
          dirName: "guides",
        },
      ],
    },
  ],
  references: [
    {
      type: "category",
      label: "References",
      link: { type: "doc", id: "references/readme" },
      items: [
        {
          type: "autogenerated",
          dirName: "references",
        },
      ],
    },
  ],
  examples: [
    {
      type: "category",
      label: "Examples",
      link: { type: "doc", id: "examples/readme" },
      items: CategoriesExamples.map((val) => {
        const dashVal = val.replaceAll(" ", "-");
        return {
          label: val,
          type: "link",
          href: `#${dashVal}`,
        };
      })
    },
  ],
  nodes: [
    {
      type: "category",
      label: "Nodes",
      link: { type: "doc", id: "nodes/readme" },
      items: CategoriesNodes.map((val) => {
        const dashVal = val.replaceAll(" ", "-");
        return {
          label: val,
          type: "link",
          href: `#${dashVal}`,
        };
      })
    },
  ],
};

module.exports = sidebars;
